
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[gspSiteUser_SEARCH]
(
@userId int = null,
@userName nvarchar(100) = null,
@email nvarchar(100) = null,
@password nvarchar(128) = null,
@passwordSalt nvarchar(128) = null,
@comments nvarchar(256) = null,
@createdDate datetime = null,
@lastModifiedDate datetime = null,
@lastLoginDate datetime = null,
@lastLoginIp nvarchar(40) = null,
@isActivated bit = null,
@isLockedOut bit = null,
@isDeleted bit = null,
@lastLockedOutDate datetime = null,
@lastLockedOutReason nvarchar(256) = null,
@newPasswordKey nvarchar(128) = null,
@newPasswordRequested datetime = null,
@newEmail nvarchar(100) = null,
@newEmailKey nvarchar(128) = null,
@newEmailRequested datetime = null
)
AS

SELECT
  *
FROM
  [dbo].[SiteUser]
WHERE
  (@userId IS NULL OR [UserId] = @userId)
AND
  (@userName IS NULL OR @userName = '' OR [UserName] LIKE @userName + '%')
AND
  (@email IS NULL OR @email = '' OR [Email] LIKE @email + '%')
AND
  (@password IS NULL OR @password = '' OR [Password] LIKE @password + '%')
AND
  (@passwordSalt IS NULL OR @passwordSalt = '' OR [PasswordSalt] LIKE @passwordSalt + '%')
AND
  (@comments IS NULL OR @comments = '' OR [Comments] LIKE @comments + '%')
AND
  (@createdDate IS NULL OR [CreatedDate] = @createdDate)
AND
  (@lastModifiedDate IS NULL OR [LastModifiedDate] = @lastModifiedDate)
AND
  (@lastLoginDate IS NULL OR [LastLoginDate] = @lastLoginDate)
AND
  (@lastLoginIp IS NULL OR @lastLoginIp = '' OR [LastLoginIp] LIKE @lastLoginIp + '%')
AND
  (@isActivated IS NULL OR [IsActivated] = @isActivated)
AND
  (@isLockedOut IS NULL OR [IsLockedOut] = @isLockedOut)
AND
  (@isDeleted IS NULL OR [IsDeleted] = @isDeleted)
AND
  (@lastLockedOutDate IS NULL OR [LastLockedOutDate] = @lastLockedOutDate)
AND
  (@lastLockedOutReason IS NULL OR @lastLockedOutReason = '' OR [LastLockedOutReason] LIKE @lastLockedOutReason + '%')
AND
  (@newPasswordKey IS NULL OR @newPasswordKey = '' OR [NewPasswordKey] LIKE @newPasswordKey + '%')
AND
  (@newPasswordRequested IS NULL OR [NewPasswordRequested] = @newPasswordRequested)
AND
  (@newEmail IS NULL OR @newEmail = '' OR [NewEmail] LIKE @newEmail + '%')
AND
  (@newEmailKey IS NULL OR @newEmailKey = '' OR [NewEmailKey] LIKE @newEmailKey + '%')
AND
  (@newEmailRequested IS NULL OR [NewEmailRequested] = @newEmailRequested)


GO
